<?php

/*
Plugin Name: Google Analytics
Plugin URI: 
Description: Include Google Analytics code at the appropriate spot
Version: 0.1
Author: Docunext
Author URI: http://www.docunext.com
*/

/*
*
*       Google Analytics
*
*               Copyright 2006 Albert Lash / Savonix  (http://www.savonix.com)
* 		License: LGPL http://www.gnu.org/licenses/lgpl.html
*
*/


function outbound_link_tracker() { 
?>
<script src="http://www.docunext.com/js/link-tracker.js" type="text/javascript">
</script>
<?php
}

function output_analytics_code() { 

$uacct = get_option('analytics_id');

?>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "<?php echo $uacct; ?>";
urchinTracker();
</script>

<?php
}




function analytics_admin_pages() {
        if (current_user_can('manage_options')) {
                add_options_page(__("Analytics"), __("Analytics"), 8, 'analytics_options', 'analytics_options');
        }
}

function analytics_options() { 


if ($_POST) {

	update_option('analytics_id',$_POST['analytics_id']);

}
$my_analytics_id = get_option('analytics_id');
?>
<div>
<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
Analytics Account ID: <input type="text" name="analytics_id" value="<?php echo $my_analytics_id;?>"/><br/>
<input type="submit"/>
</form>

</div>


<?php
}

add_action('wp_head', 'outbound_link_tracker');

add_action('admin_menu','analytics_admin_pages');

add_action('wp_footer', 'output_analytics_code');
?>
